package formatter;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;
import java.util.ResourceBundle;

import banking.*;

public class TextPlainFormatter  implements IStatementFormater {

	private StringBuffer sb;
	ResourceBundle bundle;
	Locale currentLocale;
	NumberFormat numberFormatter;
	DateFormat dateFormatter;
	Currency currency;
	
	
	public TextPlainFormatter(){
		sb = new StringBuffer();
	}
				
				
	@Override
	public void addData(Account account) {
		currentLocale = new Locale(account.getCountry(), account.getLanguage());
		bundle = ResourceBundle.getBundle("props/local", currentLocale);
		numberFormatter = NumberFormat.getCurrencyInstance(currentLocale);
		dateFormatter = DateFormat.getDateTimeInstance(DateFormat.FULL,
				DateFormat.MEDIUM, currentLocale);
		currency = Currency.getInstance(currentLocale);

		sb.append(bundle.getString("accountNumber") + ":" + account.getAccountNumber() + "\n");
		sb.append(bundle.getObject("name") + ":" + account.getAccountHolder() + "\n");
		for(Statement str : account.getBookList()){
		sb.append(bundle.getObject("date") + ":" + dateFormatter.format(str.getDate()) + "\n");
		sb.append(bundle.getObject("reason") + ":" + str.getReason() + " ");
		sb.append(bundle.getObject("value") + ":" + str.getValue() + " " + currency.getSymbol() + " ");
		}
	}
	
	public String getFormattedText(){
		return sb.toString();
	}
}
